package com.example.chapter12;

public class Demo01 {

    public static int num = 0;

    public synchronized static void add(){
        num++;
    }

    public static class T extends Thread{
        @Override
        public void run() {
            for (int i = 0;i < 1000;i++){
                add();
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        T t1 = new T();
        T t2 = new T();
        T t3 = new T();
        t1.start();
        t2.start();
        t3.start();
        t1.join();
        t2.join();
        t3.join();
        System.out.println(Demo01.num);
    }
}
